<template>
	<view class="container">
		<u-toast ref="uToast" />
		<u-navbar :is-back="false" title="我的班级" back-icon-color='#333333' height="50" :border-bottom="false">
			<text class="iconfont icon-fanhuijian2" style="font-size:30rpx; margin-left:30rpx; font-weight:bold;"
				@click="previous_pages"></text>
		</u-navbar>
		<view class="list">
			<view class="class_list" v-for="(item,index) in classList" :key="index"
				@click.stop="$toLink('../my_schedule/my_schedule',{id:item.classes_id,class:item.classes_name})">
				<view class="left">
					<image src="../../static/tupian116.png" mode="widthFix"></image>
				</view>
				<view class="center">
					<view class="top">
						<text>{{item.classes_name}}</text>
					</view>
					<view class="bottom">
						<image src="../../static/tupian114.png" mode="widthFix"></image>
						<text>{{item.student_count}}人</text>
					</view>
				</view>
				<view class="right">
					<image src="../../static/tupian93.png" mode="widthFix"></image>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import request from '../../request.js'
	export default {
		data() {
			return {
				class_list: [],
				back_page: 1,
			}
		},
		onLoad(option) {
			if (option.id) {
				switch (option.id) {
					case 1:
						this.back_page = 1;
						break;
					case 2:
						this.back_page = 2;
						break;
					case 3:
						this.back_page = 3;
						break;
				}
			}
			this.myClasses();
		},
		computed: {
			classList() {
				if (this.class_list) {
					return this.class_list;
				} else {
					return [];
				}
			}
		},
		methods: {
			//对返回上一级页面分情况跳转
			previous_pages() {
				switch (this.back_page) {
					case 1:
						this.$toLink('../career/career', {}, 3)
						break;
					case 2:
						uni.navigateBack({
							delta: 1
						})
						break;
					case 3:
						break;
				}
			},
			myClasses() {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let _this = this;
				request({
					url: base_url + 'teacher/user/myClasses',
					method: 'get',
					success(res) {
						if (res.statusCode == 200) {
							console.log(res.data.data);
							_this.class_list = res.data.data;
						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.container {
		width: 100%;
		background: #F2F2F2;

		.list {
			width: 100%;
			overflow: hidden;

			.class_list {
				box-shadow: 0px 1px 1px 1px #ccc;
				width: 710rpx;
				height: 130rpx;
				margin-left: 20rpx;
				background: #fff;
				display: flex;
				align-items: center;
				justify-content: flex-start;
				border-radius: 12rpx;
				margin-top: 20rpx;

				.left {
					width: 72rpx;
					margin-left: 20rpx;

					image {
						&:nth-child(1) {
							width: 70rpx;
						}
					}
				}

				.center {
					width: 520rpx;
					margin-left: 20rpx;
					height: 90rpx;
					overflow: hidden;

					.top {
						width: 100%;
						display: flex;
						align-items: center;
						justify-content: flex-start;
						font-size: 30rpx;
						color: #333333;
					}

					.bottom {
						width: 100%;
						margin-top: 20rpx;
						height: 35rpx;
						display: flex;
						align-items: center;
						justify-content: flex-start;

						image {
							&:nth-child(1) {
								width: 30rpx;
							}
						}

						text {
							&:nth-child(2) {
								color: #333333;
								margin-left: 20rpx;
								font-size: 26rpx;
							}
						}
					}
				}

				.right {
					margin-left: 30rpx;

					image {
						&:nth-child(1) {
							width: 20rpx;
						}
					}
				}
			}
		}
	}
</style>
